from django.shortcuts import render
from rest_framework.response import Response
from rest_framework.views import APIView
from rest_framework.permissions import IsAuthenticated
from coupon.services import get_user_coupons_list,get_user_valid_coupons_list
# Create your views here.

class CouponList(APIView):
    # DRF中用于控制API访问权限的类
    permission_classes = [IsAuthenticated]

    def get(self, request):
        user_id = request.user.id
        # 调用get_user_coupons_list函数获取用户的优惠券列表
        coupon_list = get_user_coupons_list(user_id)
        return Response({"messgae":"优惠券列表获取成功","coupon":coupon_list})


class CouponValidList(APIView):
    # DRF中用于控制API访问权限的类
    permission_classes = [IsAuthenticated]
    def post(self, request):
        user_id = request.user.id
        doctor_id = request.data.get("doctor_id")
        # 调用get_user_valid_coupons_list函数获取用户有效的优惠券列表
        valid_coupon_list = get_user_valid_coupons_list(user_id,doctor_id)
        print(valid_coupon_list)
        return Response({"message":"有效优惠券列表获取成功","coupon":valid_coupon_list})